function orderlyQueue(s: string, k: number): string {
    if (k>1) {
        let numArr: number[] = s.split('').map(item =>  item.charCodeAt(0))
        numArr.sort((a,b) => a-b)
        const strArr: string[] = numArr.map(item => String.fromCharCode(item))
        return strArr.join('')
    }else {
        let ans = s
        for (let i=0;i<s.length-1;i++){
            s = s.substring(1) + s[0]
            ans = ans > s ? s : ans
        }
        return ans
    }
};


// function orderlyQueue(s: string, k: number): string {
//     let numArr: number[] = s.split('').map(item =>  item.charCodeAt(0))
//     if (k>1) {
//         numArr.sort((a,b) => a-b)
//         const strArr: string[] = numArr.map(item => String.fromCharCode(item))
//         return strArr.join('')
//     }else {
//         const minNum = Math.min(...numArr)
//         const minArr: string[][] = []
//         for(let i=0;i<numArr.length;i++){
//             if (numArr[0] === minNum) {
//                 minArr.push(numArr.map(item => String.fromCharCode(item)))
//             }
//             const item = numArr.shift()
//             numArr.push(item as number)
//         }
//         let min: string[] = minArr[0]
//         console.log(minArr)
//         for (let index in minArr) {
//             if (judge(min,minArr[index])) {
//                 min = minArr[index]
//                 console.log(min.join(''))
//             }
//         }
//         return min.join('')
//     }
    
// };

// function judge(arr1: string[], arr2: string[]): boolean {
//     for(let i=0;i<arr1.length;i++) {
//         if (arr1[i].charCodeAt(0)>arr2[i].charCodeAt(0)){
//             return true
//         }else if (arr1[i].charCodeAt(0)<arr2[i].charCodeAt(0)){
//             return false;
//         }
//     }
//     return false;
// }

const s = 'xitavoyjqiupzadbdyymyvuteolyeerecnuptghlzsynozeuuvteryojyokpufanyrqqmtgxhyycltlnusyeyyqygwupcaagtkuq'
const k = 1
console.log(orderlyQueue(s,k))